package net.aiform.account.service;

import java.util.List;

import org.apache.log4j.Logger;

import net.aiform.account.dao.PersonDao;
import net.aiform.account.pojo.Person;

public class PersonServiceImpl implements PersonService {
	private Logger log = Logger.getLogger(this.getClass());
	PersonDao personDao;

	public List<Person> findByCode(String code) {
		return personDao.findByCode(code);
	}

	public void save(Person person) {
		personDao.save(person);
	}

	public void remove(String id) {
		personDao.remove(id);
	}

	public Person find(String id) {
		return personDao.find(id);
	}

	@Override
	public boolean isAvailable(String name) {
		List<Person> ps = this.findByCode(name);
		return ps.size() == 0 ? true : false;
	}

	public PersonDao getPersonDao() {
		return personDao;
	}

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	@Override
	public Person login(Person person) {
		log.info(person.toString());
		return this.personDao.getByCodeAndPassword(person.getCode(), person.getPassword());
	}

}
